package com.ruoyi.project.wms.outgoods.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.wms.outgoods.domain.WmsOutGoods;
import com.ruoyi.project.wms.outgoods.service.IWmsOutGoodsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2020-10-03
 */
@Controller
@RequestMapping("/wms/outgoods")
public class WmsOutGoodsController extends BaseController
{
    private String prefix = "wms/outgoods";

    @Autowired
    private IWmsOutGoodsService wmsOutGoodsService;

    @RequiresPermissions("wms:outgoods:view")
    @GetMapping()
    public String goods()
    {
        return prefix + "/goods";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("wms:outgoods:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WmsOutGoods wmsOutGoods)
    {
        startPage();
        List<WmsOutGoods> list = wmsOutGoodsService.selectWmsOutGoodsList(wmsOutGoods);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("wms:outgoods:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WmsOutGoods wmsOutGoods)
    {
        List<WmsOutGoods> list = wmsOutGoodsService.selectWmsOutGoodsList(wmsOutGoods);
        ExcelUtil<WmsOutGoods> util = new ExcelUtil<WmsOutGoods>(WmsOutGoods.class);
        return util.exportExcel(list, "goods");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("wms:outgoods:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WmsOutGoods wmsOutGoods)
    {
        return toAjax(wmsOutGoodsService.insertWmsOutGoods(wmsOutGoods));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{ogid}")
    public String edit(@PathVariable("ogid") Long ogid, ModelMap mmap)
    {
        WmsOutGoods wmsOutGoods = wmsOutGoodsService.selectWmsOutGoodsById(ogid);
        mmap.put("wmsOutGoods", wmsOutGoods);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("wms:outgoods:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WmsOutGoods wmsOutGoods)
    {
        return toAjax(wmsOutGoodsService.updateWmsOutGoods(wmsOutGoods));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("wms:outgoods:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wmsOutGoodsService.deleteWmsOutGoodsByIds(ids));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("wms:outgoods:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/outStore")
    @ResponseBody
    public AjaxResult outStore(String ids)
    {
        String[] strs = Convert.toStrArray(ids);
        String onum = strs[0];
        return toAjax(wmsOutGoodsService.outStore(onum));
    }
}
